var mysql = require('mysql');
var connection = mysql.createConnection({
    host: 'localhost',
    port: 3306,
    user: 'root',
    password: 'root',
    database: 'crud'
});

connection.connect( (err) => {
    if (!err) {
        console.log("数据库链接成功");
    } else {
        console.log("数据库链接失败");
    }
});

function login(sql) {
    return new Promise((resolve, reject) => {
        connection.query(sql, (err, data) => {
            resolve(data);
        })
    })
};
function registry(sql) {
    return new Promise((resolve, reject) => {
        connection.query(sql, (err, data) => {
            resolve(data);
        })
    })
};
function updata(sql) {
    return new Promise((resolve, reject) => {
        connection.query(sql, (err, data) => {
            resolve(data);
        })
    })
};
module.exports = {login,registry,updata};